﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;

namespace Database.Models
{
    [Table("User")]
    public class User : BaseModel
    {
        public User()
        {
            Roles = new HashSet<Role>();
        }

        public int Id { get; set; }

        [Required]
        [MaxLength(255)]
        public string Username { get; set; }

        [Required]
        [MaxLength(255)]
        public string Password { get; set; }

        [Required]
        [MaxLength(255)]
        public string FullName { get; set; }
        public int? CreatedById { get; set; }
        
        //public DateTime Created { get; set; }
        //public virtual User CreatedBy { get; set; }
        //public DateTime Modified { get; set; }
        //public virtual User ModifiedBy { get; set; }

        public int? ModifiedById { get; set; }
        

        public virtual ICollection<Role> Roles { get; set; }

        [NotMapped]
        public string UserRole
        {
            get
            {
                string userRole = string.Empty;
                if (Roles != null && Roles.Count > 0)
                {
                    userRole = Roles.Aggregate(userRole, (current, role) => string.Concat(role.RoleName, "; ", current));
                }
                return userRole;
            }
        }
    }
}